//
//  VerifyCodeInputView.m
//  NoNeedle
//
//  Created by Ming Tian on 2017/3/21.
//  Copyright © 2017年 Ming Tian. All rights reserved.
//

#import "VerifyCodeInputView.h"


@implementation VerifyCodeInputView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setHidden:(BOOL)hidden {
    [super setHidden:hidden];
    for (UITextField *textField in self.inputView.textFieldArray) {
        textField.text = @"";
        [textField endEditing:YES];
    }
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self setHidden:YES];
}

- (void)setupSubviews {
    self.bgView = [[UIView alloc]init];
    self.titleLabel = [[UILabel alloc]init];
    self.inputView = [[PZXVerificationCodeView alloc]initWithFrame:CGRectMake(0, 0, 280, 280.0/6.0)];
    
    self.bgView.backgroundColor = [UIColor whiteColor];
    
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.textColor = RGB(0x666666);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = @"输入支付密码";
    
    self.inputView.VerificationCodeNum = 6;
    self.inputView.deselectColor = RGB(0x666666);
    self.inputView.selectedColor = RGB(0x666666);
    self.inputView.Spacing = 0;
    self.inputView.isSecure = YES;
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    
    [self addSubview:self.bgView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.inputView];
    
    [self setupConstraints];
}

- (void)setupConstraints {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(117);
        make.bottom.equalTo(self).offset(-300);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.bgView);
        make.top.equalTo(self.bgView).offset(15);
    }];
    
    [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
        make.left.equalTo(self.bgView).offset(10);
        make.right.equalTo(self.bgView).offset(-10);
        make.height.mas_equalTo(280.0/6.0);
    }];
}

@end
